// pages/asc/kechenginfo/kechenginfo.js
var _utils = require('../../../utils/utils.js')
var _http = require('../../../utils/httpUtils.js')
Page({

    /**
     * 页面的初始数据
     */
    data: {
        tabsId: 1,//底部的tabs  id
        formatTabsId: 1,//底部tabs 里面的tabs id
        ked: "<p>College Courses for Credits</p><p>SJTU Online Sessions provide a broad range of credit courses strictly following the academic standards by American universities. The courses are taught by college professors from United States during the year.</p><p>Students who complete the courses would receive up to four credits per course transferable to most of the universities in United States.&nbsp;</p><p>Features:</p><p>-\tEarn credits to save for your college</p><p>-\tProfessors from American universities&nbsp;</p><p>-\tHave more flexibility to attend classes anywhere of your choice</p><p>Advantage:</p><p>-\tCredits transferable to U.S. colleges</p><p>-\tCheaper credits, cheaper college expenses</p><p>-\tPermanent records at SJTU</p><p>-\tFirst-class online platform for teaching and exams</p><p>Benefits:</p><p>-\tCredits</p><p>-\tSave money</p>"
        ,
        kcId: "",
        kcInfo:{},
        source:1,
        status:-1,
        tagStyle : {
            pre: 'padding:1em 1em 0 1em;margin:.5em 0;border-radius:0.3em;background:#272822;color:#f8f8f2;line-height: 1.5;text-shadow:0 1px rgba(0,0,0,0.3);font-family:Consolas,Monaco,"Andale Mono","Ubuntu Mono",monospace;position:relative',
            code: 'background-color:#f0f0f0;font-size:85%;margin:0 3px;padding:2px 5px 2px 5px;border-radius:2px;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace'
        },
        
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var id = options.id;
        console.log("从首页过来的id:", id);
        // id = 1;
        this.setData({
            kcId: id,
            token: wx.getStorageSync('token'),
            payStatus:options.payStatus,
            // status:wx.getStorageSync('eStatus')
        })


        
        //查询课程详情
        getKCDetail(this);

    },
    clickTabs: function (e) {
        var id = e.currentTarget.dataset.id;
        this.setData({
            tabsId: id
        })
    },
    showSignUpPage: function () {
        console.log("去注册页面");
        //未登录去注册页面
        var kc = this.data.kcInfo;
        getApp().other = {t:kc.tutor.cn_name,p:kc.cate_name.class_name,tid:kc.id,cate_id:kc.cates_id}
        wx.switchTab({
            url: '/pages/asc/apple/appleType/appleType',
        })
    },
    clickFormatTabs: function (e) {
        var id = e.currentTarget.dataset.id;
        this.setData({
            formatTabsId: id
        })
    },
    toPay: function () {
        var _this = this;
        _utils.toast("",2);
        //生成订单去支付
        _http.post(_http.addOrder,{course_id:this.data.kcId,source:this.data.source},function(res){
            if(res.status == 1){
                wx.navigateTo({
                    url: '../kechengPay/kechengPay?order_no='+res.data.order_no,
                    success: function (res) { },
                    fail: function (res) { },
                    complete: function (res) { },
                })
            }else{
                _utils.toast(res.msg);
            }
        })

       
    },
    // 链接点击事件
  linkpress2(e) {
    console.log(e);
    if (e.detail.href) {
    //   if (e.detail.href.includes('.doc')) {
        e.detail.ignore(); // 禁用自动复制
        wx.showLoading({
          title: '附件下载中',
        })
        wx.downloadFile({
          url: e.detail.href,
          success(res) {
            wx.hideLoading();
            wx.openDocument({
              filePath: res.tempFilePath
            })
          }
        })
    //   }
    }
  },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})

function getKCDetail(_this){
    let stat = wx.getStorageSync('eStatus');
    _http.post(_http.projectDetail,{id:_this.data.kcId},function(res){
        _this.setData({
            kcInfo:res.data.list,
            payStatus:res.data.list.is_pay

        })
        //判断课程的类型所拥有的状态
        for (let i = 0; i < stat.length; i++) {
            const st = stat[i];
            if(st.program == res.data.list.cate_name.class_name){
                _this.setData({
                    status:st.status
                })
            }
            
        }
    })
}